<?php

class HistoAdminController extends Controller
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	public $layout='//layouts/selavenir_admin';
	public $skin = "";
	
	public function init()
	{
		$session=new CHttpSession;
		$session->open();
		if (isset($session["skin"])) $this->skin = $session["skin"];
	}
	
	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
				'accessControl', // perform access control for CRUD operations
				'postOnly + delete', // we only allow deletion via POST request
		);
	}
	
	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
				array('allow', // allow authenticated user to perform 'create' and 'update' actions
						'actions'=>array('admin'),
						'expression' => array($this, 'isAdmin'),
				),
				array('deny',  // deny all users
						'users'=>array('*'),
				),
		);
	}
	
	/**
	 *  Function to control access
	 * @param CWebUser current user obj
	 * @param CAccessRule access rule obj
	 */
	public function isAdmin($user, $rule)
	{
		if(isset($user->admin) && $user->admin)
			return true;
		else
			return false;
	}
	
	public function actionAdmin()
	{
		$model=new HistoAdmin('search');
		$model->unsetAttributes();  // clear any default values
		if(isset($_GET['HistoAdmin']))
			$model->attributes=$_GET['HistoAdmin'];

		$this->render('admin',array(
			'model'=>$model,
		));
	}
	
	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer $id the ID of the model to be loaded
	 * @return Seliste the loaded model
	 * @throws CHttpException
	 */
	public function loadModel($id)
	{
		$model=HistoAdmin::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

}